#include "poker.h"
#include <QDebug>

Poker::Poker(QWidget *parent ,int index_v,QSize size,int len_v):
    QWidget(parent),index(index_v),label(new QLabel(this)),pix(QString(":/poker/poker/%1.jpg").arg(index_v)),len(len_v)
{
    if(pix.isNull()){
        qDebug() << "没有找到图片";
    }
    isUp = false;
    this->resize(size);
    label->setPixmap(pix.scaled(size));
    label->resize(size);
    this->canClick = true;
    //this->move(100,120);
    //qDebug() << "label father:" << parent ;
}

void Poker::setCanClick(bool click){
    this->canClick = click;
}

bool Poker::getCanClick()const{
    return this->canClick;
}

//获取index
int Poker::getIndex() const{
    return index;
}

//点击事件，修改标签位置，并发送信号pos_changed
void Poker::mousePressEvent(QMouseEvent * event){
    if(!this->canClick) return;
    qDebug() << "点击了";
    clicked_my();
    emit pos_changed(isUp,this);
}

bool Poker::getIsUp() const{
    return this->isUp;
}

//点击事件的实现
void Poker::clicked_my(){
    //上下来回
    if(isUp){
        this->move(this->x(),this->y()+len);
        isUp = false;
    }else{
        this->move(this->x(),this->y()-len);
        isUp = true;
    }
}

void Poker::reset_Pixmap(int index_v){
    label->setPixmap(QPixmap(QString(":/poker/poker/%1.jpg").arg(index_v)).scaled(this->size()));
    this->index = index_v;
}

//bool Poker::event(QEvent * event){
//    if(event->type() == QEvent::MouseButtonPress){
//        qDebug() << "被点击";
//        return true;
//    }
//    return QWidget::event(event);
//}
